//
//  AppGlobalDefine.h
//  industry
//
//  Created by xl on 2020/11/11.
//  Copyright © 2020 Haier. All rights reserved.
//

#ifndef AppGlobalDefine_h
#define AppGlobalDefine_h

//0关闭Log 1打开Log
#define XLLogEnable 1

//日志切换开关
#if (XLLogEnable == 1)
#define NSLog(...) NSLog(__VA_ARGS__)
//#define XLLog(format, ...)  printf("%s: %s 第%d行: %s\n\n",[[NSString lr_stringDate] UTF8String], [LRString UTF8String] ,__LINE__, [[NSString stringWithFormat:__VA_ARGS__] UTF8String]);
#define XLLog(format, ...)  XLLOGPRINT(format, ##__VA_ARGS__)

#define XLNetLog(format, ...)  XLLOGPRINT(format, ##__VA_ARGS__)

#else
#define NSLog(...)
#define XLLog(format, ...)
#define XLNetLog(NSString_format, ...)
#endif

//弱引用
#define WEAKSELF                    typeof(self) __weak weakSelf=self;
//强引用
#define STRONGSELF                  __strong __typeof(weakSelf) strongSelf = weakSelf;

//app版本
#define XLAPPVERSION         [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

//图片
#define XLIMAGE(name)               [UIImage imageNamed:name]
#define XLWebIMAGEURL(name)         [NSURL URLWithString:name]

//whether this string is empty
#define ISEmptyString(str) ([str isKindOfClass:[NSNull class]] || !str || str.length == 0)
#define ISEmptyNumber(num) ([num isKindOfClass:[NSNull class]] || !num)

//通知简写
#define XLNotif [NSNotificationCenter defaultCenter]
#define XLStandardUserDefaults [NSUserDefaults standardUserDefaults]

//代理简写
#define XLSend(instance, protocol, message) [(id<protocol>)(instance) message]

//GCD 异步主线程
#define RunAsyncOnMainThread(xxx)    dispatch_async(dispatch_get_main_queue(), ^{  \
xxx \
});

//suppress warnning
#define XLSuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)

// 防止多次调用
#define XLPreventRepeatClickTime(_seconds_) \
static BOOL shouldPrevent; \
if (shouldPrevent) return; \
shouldPrevent = YES; \
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((_seconds_) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ \
shouldPrevent = NO; \
}); \

//单例宏
// .h
#define XLShareInstance_interface(class) +(instancetype) shared##class;
// .m
#define XLShareInstance_implementation(class)         \
static class *_instance;                        \
\
+(id) allocWithZone : (struct _NSZone *) zone { \
static dispatch_once_t onceToken;           \
dispatch_once(&onceToken, ^{                \
_instance = [super allocWithZone:zone]; \
});                                         \
\
return _instance;                           \
}                                               \
\
+(instancetype) shared##class                   \
{                                           \
if (_instance == nil) {                     \
_instance = [[class alloc] init];       \
}                                           \
\
return _instance;                            \
}

//获取当前活跃窗口
#define XLKeyWindow [XLHelperTool getCurrentKeyWindow]

#endif /* AppGlobalDefine_h */
